package com.dxy;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

public class MyBatisUtil {

    public static SqlSessionFactory getSqlSessionFactory() throws IOException {
        Properties props = ConfigUtil.getProperties();
        try (InputStream is = Resources.getResourceAsStream("mybatis-config.xml")) {
            return new SqlSessionFactoryBuilder().build(is, props);
        }
    }

    public static void main(String[] args) throws IOException {
        try (SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()) {
            DbMapper mapper = session.getMapper(DbMapper.class);
            List<TableMeta> list1 = mapper.getTableName("dxy", "");
            list1.forEach(System.out::println);

            List<ColumnMeta> list2 = mapper.getColumnMeta("dxy", "t_user");
            list2.forEach(System.out::println);
        }
    }
}
